<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">门户内容管理</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>门户内容管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">栏目管理</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
      <div class="rowl" >
			<div class="col-lg-12">
	            <div class="panel" style="height: 500px;width:450px; overflow: auto;">
	                <div class="panel-heading">分类列表
	                <p style="float: right;">
	                	<button  type="button" onclick="addCategory()" class="btn btn-green btn-square" id="savejiedian">新建</button>&nbsp;
						<button  type="button" onclick="uploadCategory()" class="btn btn-green btn-square" id="savejiedian">编辑</button>&nbsp;
						<button  type="button"   class="btn btn-green btn-square"  onclick="deleteCategory()" >删除</button>
	                </p>
	                </div>
	                <div class="panel-body" >
	                	<ul id="tree" class="ztree" style="width:270px"; overflow:auto;"></ul>
	                </div>
	            </div>
	        </div>
	    </div>
	  </div>
<?} ?>
  
<SCRIPT type="text/javascript" >
	var parentname =1;
	var ztreeid = 0;
	function getzTreeid() {
		return ztreeid;
	}
	var ztreename = '根目录';
	function getztreename() {
		return ztreename;
	}
	var dictId = 10;
	function getdictId() {
		return dictId;
	}
	var dictType;
	function getdictType() {
		return dictType;
	}
	function addCategory() {
		dictType = 0;
		layer.open({
			type : 2,
			area : [ '550px', '550px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : "添加栏目",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "cms-category-addUpload.html", 'no' ],
			yes : function(index, layer) {
				 var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}
		});
	};
	//树状结构
	$(function() {
		initTree();
	});
	function get() {
		initTree();
	}

	function initTree() {
		$.ajax({
			type : "post",
			url : "cmsCategoryDictItem.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		
		$.fn.zTree.init($("#tree"), setting, zNodes);
		zTree = $.fn.zTree.getZTreeObj("tree").expandAll(true);
		//zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠

	}
	function onClick(e, treeId, treeNode) {
		ztreeid = treeNode.id;
		ztreename=treeNode.name
		dictId=treeNode.dictId
		 if(treeNode.children == null){
       		parentname=0;
       	 }else{
         	parentname=1;
        }
	}
	
	//删除
	function deleteCategory() {
	if(ztreeid ==null){
			layer.msg('请选择要删除菜单！');
		}else{
		if (parentname == 0) {
			if (confirm("是否确认删除！！")){
				$.ajax({
					type : "post",
					url : "./deldictiem.do",
					data : {
						"id" : ztreeid
					},
					dataType : "json",
					success : function(data) {
						if(data.count==1){
							ztreename="根目录";
							ztreeid=0;
							initTree();
							layer.msg('删除成功！');
						}else{
							ztreename="根目录";
							ztreeid=0;
							initTree();
							layer.msg('有关联,不可删除！');
						}
						/* loadOneTree(); */
						/* initTree(); */
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}
		}else {
			alert("有子分类不允许删除");
		}
		}
	}
	//编辑
	function uploadCategory() {
	if(ztreeid == '0'){
			layer.msg('请选择要编辑菜单！');
		}else{
			dictType = 1;
			layer.open({
				type : 2,
				area : [ '550px', '550px' ],
				fix : false, //不固定
				scrollbar : false,
				shadeClose : true,
				move : false,
				title : "编辑栏目",
				skin : 'layui-layer-rim', //加上边框
				btn : [ '保存 ', '关闭' ],
				content : [ "cms-category-addUpload.html", 'no' ],
				yes : function(index, layer) {
					 var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.Page();
				},
				cancel : function(index) {
				}
			});
		}
	};

</SCRIPT>    